#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
int t, n, maxx = 0;
vector<int> mp;
bool f = false;
void dfs(int x = 1, int t = 1) //技巧了属于是
{
    if (x > n || !mp[x])
        return;
    dfs(x * 2, t + 1);
    if (f)
        cout << " ";
    cout << mp[x];
    f = true;
    dfs(x * 2 + 1, t + 1);
    maxx = max(maxx, t);
}
int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n;
        mp.resize(n + 1); //设置容器大小
        maxx = 0;
        f = false;
        for (int i = 1; i <= n; i++)
            cin >> mp[i];
        dfs();
        cout << endl;
        cout << maxx << endl;
    }
    return 0;
}